import { mapState, useStore, mapGetters } from 'vuex';
import { computed } from 'vue';
export const useGetters = (mapper: any) => {
  const store = useStore();
  const mapFns: Record<string, any> = mapGetters(mapper);
  const state: Record<string, any> = {};
  Object.keys(mapFns).forEach(fnKey => {
    state[fnKey] = computed(mapFns[fnKey].bind({ $store: store }));
  });
  return state;
};

export const useState = (mapper: any) => {
  const store = useStore();
  const mapFns: Record<string, any> = mapState(mapper);
  const state: Record<string, any> = {};
  Object.keys(mapFns).forEach(fnKey => {
    state[fnKey] = computed(mapFns[fnKey].bind({ $store: store }));
  });
  return state;
};
